<template>
  <div class="root">
    <ad class="ad" v-show="isShowAd" :count="count" @jump="handleJump"></ad>
    <div v-show="!isShowAd">
      <router-view #default="{ Component }">
        <keep-alive>
          <component :is="Component" v-if="$route.meta.keepAlive" />
        </keep-alive>
        <component :is="Component" v-if="!$route.meta.keepAlive" />
        <!-- <component :is="Component"/> -->
      </router-view>
    </div>
  </div>
</template>
<script>
import { onMounted, ref } from "vue";
import Ad from "@/components/ad/ad.vue";
export default {
  components: {
    Ad,
  },
  setup() {
    const isShowAd = ref(true);
    const handleJump = () => {
      isShowAd.value = false;
      window.location.href = "http://tc.weilang.top/vue/";
    };
    const count = ref(5);

    onMounted(() => {
      let token = sessionStorage.getItem("token") || false;
      if (!token) {
        let timer = setInterval(() => {
          if (count.value === 0) {
            handleJump();
            clearInterval(timer);
          }
          count.value--;
        }, 1000);
        //  sessionStorage.setItem("token", "7476a3b5b3d07d39213cbd7e105252b1");
        //   sessionStorage.setItem("openid", "oO2yA1ekwniTq_J5WDS85wwJ4fSE");
      } else {
        isShowAd.value = false;
      }
    });
    
    return {
      isShowAd,
      handleJump,
      count,
    };
  },
};
</script>
<style lang="less">
@import url("./assets/css/reset.css");
@import url("./assets/css/vant_1.css");
@import url("http://at.alicdn.com/t/font_2518654_1o6o1eviu8b.css");
.root {
  padding-top: 13.333vw;
}
</style>

